package com.fc.service.impl;

import java.util.List;

import org.hibernate.Criteria
import org.hibernate.criterion.Restrictions
import org.springframework.stereotype.Repository
import org.springframework.transaction.annotation.Transactional;

import com.fc.service.MeasurementTypeService
import com.fc.entities.MeasurementType

@Repository("measurementTypeService")
@Transactional
class MeasurementTypeServiceImpl extends BaseServiceImpl<MeasurementType> implements MeasurementTypeService{
	private List<MeasurementType> measurementsTypes;

	@Override
	MeasurementType findByName(String name) {
		Criteria criteria = currentSession().createCriteria(MeasurementType.class);
		MeasurementType entity = (MeasurementType) criteria.add(Restrictions.eq("name", name)).uniqueResult();
		return entity;
	}

	@Override
	List<MeasurementType> findAll() {
		if (measurementsTypes == null) {
			measurementsTypes = findAll(MeasurementType.class);
		}
		return measurementsTypes;
	}
}
